package com.spzx.product.api.factory;

import com.spzx.common.core.domain.R;
import com.spzx.product.api.RemoteProductService;
import com.spzx.product.api.domain.ProductSkuVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @version 1.0
 * @Author 马冰
 * @Date 2025/3/3 19:10
 * @注释
 */
@Component
public class RemoteProductFallbackFactory implements FallbackFactory<RemoteProductService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteProductFallbackFactory.class);

    @Override
    public RemoteProductService create(Throwable throwable) {
        log.error("商品服务调用失败：{}", throwable.getMessage());
        return new RemoteProductService() {

            @Override
            public R<ProductSkuVo> getProductSku(Long skuId, String source) {
                return R.fail("获取商品sku失败：" + throwable.getMessage());
            }
        };
    }
}
